package com.xl6667.controller;

import com.xl6667.domain.ResponseResult;
import com.xl6667.domain.dto.HotArticleDto;
import com.xl6667.domain.entity.Article;
import com.xl6667.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("article")
@Api(tags = "文章管理",description = "文章管理API")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("/list")
    public List<Article> test(){
        return articleService.list();
    }

    /**
     * 获取热门文章
     * @return
     */
    @GetMapping("hotArticleList")
    @ApiOperation(value = "获取热门文章")
    public ResponseResult hotArticleList(){
        List<HotArticleDto> articles = articleService.hotArticleList();
        return ResponseResult.okResult(articles);
    }

    /**
     * 获取所有文章
     * @param pageNum
     * @param pageSize
     * @param categoryId
     * @return
     */
    @GetMapping("articleList")
    @ApiOperation(value = "获取所有文章")
    public ResponseResult articleList(Integer pageNum,Integer pageSize,Long categoryId){
      return   articleService.articleList(pageNum,pageSize,categoryId);
    }

    /**
     * 获取文章详细内容
     * @param id
     * @return
     */
    @GetMapping("{id}")
    @ApiOperation(value = "获取文章详细内容")
    public ResponseResult getArticle(@PathVariable Integer id){
        return articleService.getArticle(id);
    }

    @PutMapping("/updateViewCount/{id}")
    @ApiOperation(value = "更新文章浏览量")
    public ResponseResult putUpdateViewCount(@PathVariable Long id){
        return articleService.putUpdateViewCount(id);
    }
    @GetMapping("/search")
    @ApiOperation(value = "搜索文章")
    public ResponseResult searchArticle(Integer pageNum, Integer pageSize,String search){
        return articleService.searchArticle(pageNum,pageSize,search);
    }
}

